package com.lhh.springCloud.controller;

import com.lhh.entity.Member;
import com.lhh.entity.Result;
import com.lhh.springCloud.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 李洪豪
 * @Sno 20220301044
 */
@Slf4j
@RestController
public class MemberController {
    @Resource
    private MemberService memberService;
    @PostMapping("/member/save")
    //如果前端是以json格式发送数据，则使用@RequestBody接收
    //如果前端是普通表单方式提交，则不使用@RequestBody才会进行对象的封装
    public Result saveMember(@RequestBody Member member){
        int affect = memberService.addMember(member);
        if(affect > 0){
            return Result.success("添加会员成功 vipmember-service-provider-10002",affect);
        }else {
            return Result.error("4xx","添加会员失败");
        }
    }
    //根据id查询会员信息
    @GetMapping("/member/query/{id}")
    public Result queryMemberById(@PathVariable("id") Long id){
        Member member = memberService.queryMemberById(id);
        if(member != null){
            return Result.success("查询会员成功 vipmember-service-provider-10002",member);
        }else {
            return Result.error("4xx","查询会员失败");
        }
    }
}
